package edu.dev.tfile.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.ImageIcon;

import edu.dev.tfile.swing.tip.UploadTip;

public class UploadConfirmService extends HttpServlet {

	private static final long serialVersionUID = -9162221210807041541L;

	private boolean sync = false;

	private boolean allow = false;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		sync = false;
		allow = false;

		UploadTip tip = new UploadTip();
		tip.setUcs(this);
		tip.setToolTip(new ImageIcon("test.jpg"), "ANN向你发送文件XXXX.jar，是否同意?");
		while (!sync) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		resp.setContentType("text/html;charset=utf-8");
		resp.setStatus(HttpServletResponse.SC_OK);
		if (allow) {
			resp.getWriter().println("ok");
		} else {
			resp.getWriter().println("cancel");
		}
	}

	public void allowUpload(boolean flag) {
		this.sync = true;
		this.allow = flag;
	}

}
